package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.zhaocai.entity.PickExpertDetailEntity;
import com.swgk.core.recyclerview.secondary.CommonHolder;

/**
 * 专家库详情页-基本信息
 */
public class PickExpertDetailsAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private PickExpertDetailEntity pickExpertDetailEntity;

    public PickExpertDetailsAdapter(Context context, PickExpertDetailEntity pickExpertDetailEntity) {
        this.mContext = context;
        this.pickExpertDetailEntity = pickExpertDetailEntity;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = CommonHolder.get(mContext, parent, R.layout.pick_expert_details_item);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        initItem((CommonHolder) holder, position);

    }

    private void initItem(CommonHolder holder, int position) {
        View itemView = holder.getItem();

        switch (position) {
            case 0:
                chooseShowItem(itemView, pickExpertDetailEntity.getComName(), "单位");
                break;
            case 1:
                chooseShowItem(itemView, pickExpertDetailEntity.getJob(), "岗位");
                break;
            case 2:
                chooseShowItem(itemView, pickExpertDetailEntity.getAddressName(), "工作地区");
                break;
            case 3:
                chooseShowItem(itemView, pickExpertDetailEntity.getIdentityCard(), "身份证号");
                break;
            case 4:
                chooseShowItem1(itemView, pickExpertDetailEntity.getMark(), "备注");
                break;
            case 5:
                if (pickExpertDetailEntity.getCustomArray() != null && pickExpertDetailEntity.getCustomArray().size() > 0) {
                    chooseShowItem1(itemView, pickExpertDetailEntity.getCustomArray().get(0).getVal(), pickExpertDetailEntity.getCustomArray().get(0).getLabel());
                }
                break;
            case 6:
                if (pickExpertDetailEntity.getCustomArray() != null && pickExpertDetailEntity.getCustomArray().size() > 1) {
                    chooseShowItem1(itemView, pickExpertDetailEntity.getCustomArray().get(1).getVal(), pickExpertDetailEntity.getCustomArray().get(1).getLabel());
                }
                break;
            case 7:
                if (pickExpertDetailEntity.getCustomArray() != null && pickExpertDetailEntity.getCustomArray().size() > 2) {
                    chooseShowItem1(itemView, pickExpertDetailEntity.getCustomArray().get(2).getVal(), pickExpertDetailEntity.getCustomArray().get(2).getLabel());
                }
                break;
            case 8:
                if (pickExpertDetailEntity.getCustomArray() != null && pickExpertDetailEntity.getCustomArray().size() > 3) {
                    chooseShowItem1(itemView, pickExpertDetailEntity.getCustomArray().get(3).getVal(), pickExpertDetailEntity.getCustomArray().get(3).getLabel());
                }
                break;
            case 9:
                if (pickExpertDetailEntity.getCustomArray() != null && pickExpertDetailEntity.getCustomArray().size() > 4) {
                    chooseShowItem1(itemView, pickExpertDetailEntity.getCustomArray().get(4).getVal(), pickExpertDetailEntity.getCustomArray().get(4).getLabel());
                }
                break;
        }
    }

    private void chooseShowItem(View view, String itemValue, String itemTitle) {
        TextView tVTitle = view.findViewById(R.id.item_title);
        TextView tVContent = view.findViewById(R.id.item_content);

        if (!TextUtils.isEmpty(itemValue)) {
            view.findViewById(R.id.item_layout).setVisibility(View.VISIBLE);
            tVContent.setText(itemValue);
            tVTitle.setText(itemTitle);
        } else {
            view.findViewById(R.id.item_layout).setVisibility(View.GONE);
        }
        view.findViewById(R.id.ll_survey_view).setVisibility(View.GONE);
    }

    private void chooseShowItem1(View view, String itemValue, String itemTitle) {
        TextView tVTitle = view.findViewById(R.id.survey_title);
        TextView tVContent = view.findViewById(R.id.survey_view);

        if (!TextUtils.isEmpty(itemValue)) {
            view.findViewById(R.id.ll_survey_view).setVisibility(View.VISIBLE);
            tVContent.setText(itemValue);
            tVTitle.setText(itemTitle);
        } else {
            view.findViewById(R.id.ll_survey_view).setVisibility(View.GONE);
        }
        view.findViewById(R.id.item_layout).setVisibility(View.GONE);
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public int getItemCount() {
        return 10;
    }

}
